<template>
  <div id="office-info">
    <main-content :edit-component-name="editComponentName" :name="name" :query-condition="queryCondition"
                  :table-head="tableHead" :is-tree-table="isTreeTable" :buttons="buttons"></main-content>
  </div>
</template>

<script>
  import {mapState} from 'vuex'
  import mainContent from '../../../common/main-content'

  export default {
    components: {
      mainContent
    },
    computed: {
      ...mapState({
        buttons: state => state.manager.buttons
      })
    },
    mounted() {
      this.initQueryCondition()
    },
    methods: {
      initQueryCondition() {
        console.log(this.buttons)
        this.$set(this.queryCondition[2], 'url', this.buttons.target)
        this.$set(this.queryCondition[2], 'permission', this.buttons.id)
        this.$set(this.queryCondition[3],'url',this.buttons.children[0].children[0].target)
        this.$set(this.queryCondition[3],'permission',this.buttons.children[0].children[0].id)
        this.$set(this.queryCondition[4],'url',this.buttons.children[0].children[0].target)
        this.$set(this.queryCondition[4],'permission',this.buttons.children[0].children[0].id)
        let condition = {
          name: '归属公司',
          key: 'companyId',
          type: 'select'
        }
        this.common.request({
          url: this.buttons.target,
          param: {
            parentId: '0',
          },
          permission: this.buttons.id,
          loading:false,
          success: res => {
            if (res.code == 1) {
              this.$set(condition, 'options', this.common.isEmpty(res.data.rows) ? [] : res.data.rows)
              this.$set(this.queryCondition, this.queryCondition.length, condition)
            }
          }
        })
      }
    },
    data() {
      return {
        isTreeTable: true,
        name: '组织',
        editComponentName: 'office-edit',
        queryCondition: [{
          name: '组织名称',
          key: 'name',
          type: 'input'
        }, {
          name: '组织编码',
          key: 'code',
          type: 'input'
        }, {
          name: '上级组织',
          key: 'parentId',
          type: 'union-select'
        }, {
          name: '组织类别',
          key: 'typeId',
          type: 'union-select',
          url: 'sys/dictionaryInfo/getList',
          initValue: 'winfo_bd7ac0719ddf3a11e9b6c954e1add85a5d'
        }, {
          name: '组织级别',
          key: 'levelId',
          type: 'union-select',
          url: 'sys/dictionaryInfo/getList',
          initValue: 'winfo_bd27fd5289df3a11e9b6c954e1add85a5d'
        }],
        tableHead: [{
          name: '组织名称',
          key: 'name',
          width:'200px'
        }, {
          name: '组织编号',
          key: 'code',
          width:'150px'
        },{
          name:'上级组织',
          key:'parentName',
          width:'200px'
        },{
          name:'上级组织编号',
          key:'parentCode',
          width:'150px'
        },{
          name:'归属公司',
          key:'companyName',
          width:'200px'
        },{
          name:'归属公司编号',
          key:'companyCode',
          width:'150px'
        },{
          name:'组织级别',
          key:'level',
          width:'100px'
        },{
          name:'组织类型',
          key:'type',
          width:'100px'
        },{
          name:'主负责人',
          key:'chief',
          width:'100px'
        },{
          name:'副负责人',
          key:'deputy',
          width:'100px'
        },{
          name:'归属地区',
          key:'fullArea',
          width:'200px'
        }],
      }
    },
    name: "office-info"
  }
</script>

<style scoped>

</style>
